package com.kynnnn.cloud.springboot_quartz.controller;

import com.kynnnn.cloud.springboot_quartz.entity.ScheduleJobConfig;
import com.kynnnn.cloud.springboot_quartz.service.ScheduleJobService;
import com.kynnnn.cloud.springboot_quartz.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhudiwei
 * @Description TODO
 * @createTime 2021年10月13日
 */
@RestController
@RequestMapping("/quartz")
@Slf4j
public class QuartzController {

    @Autowired
    private ScheduleJobService scheduleJobService;

    /**
     * <h2>新增定时任务</h2>
     *
     * @param jobConfig
     * @return
     */
    @PostMapping("/insert")
    public CommonResponse<?> insert(@RequestBody ScheduleJobConfig jobConfig) {
        return scheduleJobService.insert(jobConfig);
    }

    /**
     * <h2>删除定时任务</h2>
     *
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public CommonResponse<?> delete(@PathVariable String id) {
        return scheduleJobService.delete(id);
    }

    /**
     * <h2>修改定时任务</h2>
     *
     * @param jobConfig
     * @return
     */
    @PostMapping("/update")
    public CommonResponse<?> update(@RequestBody ScheduleJobConfig jobConfig) {
        return scheduleJobService.update(jobConfig);
    }

    /**
     * <h2>暂停定时任务</h2>
     *
     * @param id
     * @return
     */
    @GetMapping("/pause/{id}")
    public CommonResponse<?> pause(@PathVariable String id) {
        return this.scheduleJobService.pause(id);
    }

    /**
     * <h2>恢复定时任务</h2>
     *
     * @param id
     * @return
     */
    @GetMapping("/resume/{id}")
    public CommonResponse<?> resume(@PathVariable String id) {
        return this.scheduleJobService.resume(id);
    }

    /**
     * <h2>查看所有定时任务</h2>
     *
     * @return
     */
    @GetMapping("/list")
    public CommonResponse<?> list() {
        return CommonResponse.success(scheduleJobService.list());
    }

}
